/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Random;
import java.util.Scanner;

/**
 * <p>Project: javase - Guess
 * <p>Powered by webrx On 2021-11-25 14:59:11
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Guess {
    public static void main(String[] args) {
        var rand = new Random();
        var num = rand.nextInt(100) + 1;
        var index = 0;
        var sc = new Scanner(System.in);
        while (true) {
            System.out.print("请输入数字：");

            if (!sc.hasNextInt()) {
                System.out.println("输入有误，请输入整数！！！");
                sc.next();
                continue;
            }
            var t = sc.nextInt();
            if (t > num) {
                System.out.printf("%d、太大了%n", ++index);
            } else if (t < num) {
                System.out.printf("%d、太小了%n", ++index);
            } else {
                System.out.printf("恭喜：你猜对了，你游戏成绩：%d分。%n", (100 - index * 10));
                break;
            }
            if (index >= 10) {
                System.out.printf("游戏失败：你超过了10次，智商太低，你游戏成绩：0分。%n");
                break;
            }
        }
    }
}
